<template>
  <el-select v-model="schoolId" @input="handleInput" :placeholder="placeholder" :disabled="disabled" :size="size" >
    <el-option
      v-for="item in taskListSearch"
      :key="item.id"
      :label="item.name"
      :value="item.id">
    </el-option>
  </el-select>
</template>

<script>
import { taskList } from '@/api/select/select'
export default {
  name: "taskSelect",
  computed: {
    schoolId: {
      get(){
        return this.$attrs.value || null
      },
      set(){}
    },
  },
  props: {
    placeholder: {
      type: String,
      default: '请选择智洗中心'
    },
    size: {
      type: String,
      default: 'small'
    },
    showAll: {
      type: Boolean,
      default: true
    },
    disabled: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      taskListSearch: [],
    }
  },
  created() {
    this.taskList()
  },
  methods: {
    taskList(){
      taskList().then(res => {
        if (res.code == 200 && res.data.length > 0) {
          let taskListSearch = Object.assign([], res.data)
          console.log(res.all == 1 , this.showAll,963)
          if (res.all == 1 && this.showAll) {
            taskListSearch.unshift({ id: null, name: '全部' }) // 给所属运营点添加全部
          }else{
            this.$emit('input', res.data[0].id)
          }
          this.taskListSearch = taskListSearch
          this.$emit('change', taskListSearch[0].id)
        } else {
          this.taskListSearch = []
          this.$emit('change', null)
        }
      })
    },
    handleInput(e){
      console.log(e,55)
      this.$emit('input', e)
      this.$emit('change', e)
    },
  }
}
</script>

<style scoped>

</style>
